package com.puppet.building182.mapper;

import com.puppet.building182.pojo.Permission;
import com.puppet.building182.pojo.VO.PermissionVO;
import org.apache.ibatis.annotations.*;


import java.util.List;

@Mapper
public interface PermissionMapper {
    @Select("select id,pname from sys_permission where parent_id=#{parentId}")
    List<PermissionVO> getAllPerms(Integer parentId);


    @Select("select sys_role_permission.permission_id from sys_role_permission where role_id = #{rid} ")
    List<Integer> getAllPermsByRid(Integer rid);

    @Select("select  sys_permission.parent_id from  sys_permission where id=#{id}")
    Integer getParentId(Integer pid);

    @Delete("delete from sys_role_permission where role_id = #{id}")
    Integer deletePerByRid(Integer id);

    Integer saveNewPerms(@Param("rid") Integer rid, @Param("ids") List<Integer> ids);


    @Select("select*from sys_permission")
    List<Permission> getAllPermission();

    @Delete("delete from sys_permission where id=#{id}")
    Integer deletePerms(Integer id);

    @Select("select*from sys_permission where id=#{id}")
    Permission getById(Integer id);

    @Update("update sys_permission set pname=#{pname},url=#{url},code=#{code},level=#{level},sort=#{sort} where id=#{id}")
    Integer updatePermission(Permission permissions);


    Integer addPermsByFile(@Param("datas") List<Permission> datas);

    List<Permission> getAllMenuPerms(@Param("userId") Integer userId,@Param("parentId") Integer parentId);


    List<String> getAllButtonPerms(Integer id);
}
